<?php


function admin_log($msg, $filename = null) {
	
	if(empty($filename)){
		$filename = "php_".date('Y-m-d').".log";
	}else{
		$filename = date('Y-m-d')."_{$filename}".".log";
	}

	$file_name = APPPATH . "logs/{$filename}";
	$msg = "[Date: ".date("Y-m-d H:i:s")."]\n".$msg."\n\n";
	file_put_contents($file_name,$msg,FILE_APPEND);
}



function get_start_from_file($filename)
{
	$file_name = APPPATH . "logs/{$filename}";	
	$start_file=fopen($file_name,"r");
	$start= trim(fgets($start_file)) ;
	fclose($start_file);
	return $start ;
}


function write_start_to_file($filename,$number)
{
	$file_name = APPPATH . "logs/{$filename}";
	$start_file=fopen($file_name,"w");
	fwrite($start_file,$number) ;
	fclose($start_file);
}

function echo_all($string)
{
	echo $string.PHP_EOL ;
}

function echo_500($string)
{
	if(strlen($string)<2000)
	{
		echo $string.PHP_EOL ;
	}
	else
	{
		echo substr($string, 0,2000).PHP_EOL ;
	}
}

function echo_exit_all($string)
{
	echo $string.PHP_EOL ;
	exit();
}

function echo_exit_2000($string)
{
	if(strlen($string)<2000)
	{
		echo $string.PHP_EOL ;
	}
	else
	{
		echo substr($string, 0,2000).PHP_EOL ;
	}
	exit();
}

function admin_log111($msg, $filename = null) {

	$file_name = APPPATH . "logs/{$filename}";
	$msg = $msg."\r\n";
	file_put_contents($file_name,$msg,FILE_APPEND);
}

